using UnityEngine;
using YooAsset;

namespace YooAssetsSystem.Patch
{
	/// <summary>
	/// 清理包所有缓存文件
	/// </summary>
	public class ClearPackageAllCacheBundleFilesNode : BasePatchNode
	{
		public override void OnEnter()
		{
			var package = YooAssets.GetPackage(Owner.Package);
			var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearAllBundleFiles);
			 operation.Completed += delegate(AsyncOperationBase operationBase)
			 {
                if (operation.Status == EOperationStatus.Succeed)
                {
                    machine.ChangeState<CreateDownloadNode>();
                }
                else
                {
                    Debug.LogError(operation.Error);
                    Owner.Event.UpdateFailedEvent?.Invoke($"{GetType().Name}清理失败");
                }
            };
		}
	}
}